import pytest
import yaml
import subprocess #可以在函数中嵌入执行终端的命令，allure的报告生成，自动打开类的
from utils.fixture import *

@pytest.fixture(scope='module')
def test_data():
    with open('tests/resources/test_data.yaml') as f:
        data = yaml.safe_load(f)
    return data

def pytest_sessionfinish(session, exitstatus):
    """测试会话结束后执行"""
    print('执行钩子函数')
    try:
        # subprocess.run("cd .\tests\testcase\login_page_cases\reports",shell=True, check=True) #切换目录
        #subprocess.run("allure generate ./tests/testcase/login_page_cases/reports/allure-results -o ./tests/testcase/login_page_cases/reports/allure-report --clean", shell=True, check=True)
        #上面的命令没有执行不知到subprocess，我的用法可能是出错了
        #subprocess.run("allure open ./tests/testcase/login_page_cases/reports/allure-report",shell=True, check=True)
    except subprocess.CalledProcessError as e:
        print(f"错误的报告{e}")#f应该和语法填充有关系